<!--
 * @Author: Chuckie
 * @Email: chuckie@aliyun.com
 * @Date: 2022-11-10 14:35:49
 * @LastEditTime: 2022-11-12 14:32:09
 * @Description: 
 * @FilePath: /zl-web/src/views/basic/enterprise/detail.vue
 *  
-->
<template>
  <div class="app-container">
    <el-form :model="state.form" label-width="120px">

      <el-form-item :label="$t('policy.table.policyName')">
        <el-input v-model="state.form.name" />
      </el-form-item>

      <el-form-item label="权限描述">
        <el-input v-model="state.form.description" />
      </el-form-item>


      <el-form-item label="权限标识">
        <el-input v-model="state.form.perms" />
      </el-form-item>


      <el-form-item :label="$t('sysDictInfo.search.type')">
        <el-radio-group v-model="state.form.type" class="ml-4">
          <el-radio label="1">菜单</el-radio>
          <el-radio label="2">页面</el-radio>
          <el-radio label="3">按钮</el-radio>
        </el-radio-group>



      </el-form-item>
      <el-form-item v-show="state.form.type == '2'" label="权限访问路径">
        <el-input v-model="state.form.url" />
      </el-form-item>

      <el-form-item :label="$t('policy.table.order')">
        <el-input v-model="state.form.orderNum" />
      </el-form-item>

      <el-form-item label="图标">
        <el-input v-model="state.form.icon" />
      </el-form-item>
      <!-- <el-form-item :label="$t('systemConfig.table.state')">
        <el-select v-model="state.form.status">
          <el-option v-for="(value, key) in state.dictStatus" :key=parseInt(key) :label=value :value=parseInt(key) />
        </el-select>
      </el-form-item> -->

      <el-form-item>
        <el-button type="primary" @click="onSubmit">{{$t('common.button.save')}}</el-button>
        <el-button @click="onCancel">{{$t('common.button.back')}}</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script setup lang="ts">
import { create } from './api/base-policy'
const route = useRoute()
const router = useRouter()

const { proxy }: any = getCurrentInstance()
const state = reactive({
  form: {
    id: "",
    name: "",
    description: "",
    url: "",
    perms: "",
    parentId: "",
    type: "",
    orderNum: "",
    icon: "",
    status: "",
    createBy: "",
    modifyBy: "",
    gmtCreate: "",
    gmtmodify: "",
  },
  dictPolicy: { "0": '顶级权限' },
  dictPolicyType: {
    '0': '目录', '1': '菜单', '2': '按钮'
  },
  dictStatus: {
    '1': '有效',
    '2': '删除',
  }
})

const onCancel = () => {
  router.back()
}

const onSubmit = async () => {
  
    state.form.parentId = String(route.params.id)
    const data = await create(state.form)
    proxy.$message({ message: proxy.$t('common.message.saveSuccessfully'), type: 'success' })
    state.form.id = "";
    state.form.name = "";
    state.form.description = "";
    state.form.url = "";
    state.form.perms = "";
    state.form.parentId = "";
    state.form.type = "";
    state.form.orderNum = "";
    state.form.icon = "";
    state.form.status = "";
    state.form.createBy = "";
    state.form.modifyBy = "";
    state.form.gmtCreate = "";
    state.form.gmtmodify = "";
    router.back();
  
}



onMounted(() => {
})

</script>

<style lang="scss" scoped>
.el-input {
  width: 300px;
}

.el-select {
  width: 300px;
}

.el-textarea {
  width: 300px;
}
</style>
